package com.lb.juc;

import java.util.concurrent.TimeUnit;

/**
 * @author jzhang
 * @version 1.0
 * @date 2022-12-26 11:32
 */
public class HelloVolatile {
    volatile boolean running = true;

    void m() {
        System.out.println("m:start");
        while (running) {

        }
        System.out.println("m:end");
    }

    public static void main(String[] args) {
        HelloVolatile hv = new HelloVolatile();

        new Thread(hv::m, "t1").start();

        try {
            TimeUnit.SECONDS.sleep(1);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        hv.running = false;
    }
}
